from DrissionPage import Chromium, ChromiumOptions, SessionOptions
import requests
import json

seller_id = '61381e3eda7b520001533a03'
base_url = "https://ad.xiaohongshu.com/api/leona/rtb"


headers = {
    "accept": "application/json, text/plain, */*",
    "accept-language": "zh-CN,zh;q=0.9",
    "content-type": "application/json",
    "origin": "https://ad.xiaohongshu.com",
    "priority": "u=1, i",
    "referer": f"https://ad.xiaohongshu.com/aurora/ad/manage/unit?vSellerId={seller_id}",
    "sec-ch-ua": "\"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36",
    "v-seller-id": seller_id,
    # "x-b3-traceid": "600c082c35d49677"
}

tab = Chromium().latest_tab
tab.get('https://ad.xiaohongshu.com/aurora/ad/manage/unit?vSellerId=61381e3eda7b520001533a03')  # 访问网址，这行产生的数据包不监听
unit_dict_cookie = tab.cookies(all_info=False).as_dict()

unit_url = f"{base_url}/unit/batch/bid"

data = {
    "unitIds": [
        257597585
    ],
    "eventBid": 160
}
data = json.dumps(data, separators=(',', ':'))
response = requests.post(url=unit_url, headers=headers, cookies=unit_dict_cookie, data=data)

print(response.text)
print(response)

